package com.sita.tboard.util;

/**
 * Created by lijuan zhang on 2016/1/14.
 */
public class BluetoothDataAnalysis {
    public static String s_speed;
    public static String s_rpm;
    public static String s_trip;
    public static String s_total;
    public static String s_shift;
    public static String s_oil;
    byte[] data;


    public BluetoothDataAnalysis(byte[] data) {
        this.data = data;
        extractBluetoothData(data);
    }


    public void extractBluetoothData(byte[] data) {

        if (data[0] != '<') {
            return;
        }
        s_speed = new String(data, 1, 3);
        s_speed = String.valueOf(Integer.parseInt(s_speed));
        s_rpm = new String(data, 5, 3);//小盘要乘100
        s_total = new String(data, 9, 6);
        s_trip = new String(data, 16, 4);
        s_shift = new String(data, 21, 1);
        s_oil = new String(data, 23, 4);

        System.out.println("speed:" + s_speed + "rpm:" + s_rpm + "total:" + s_total + "trip:" + s_trip + "shift:" + s_shift + "oil:" + s_oil);

        // Random data
        long time = System.currentTimeMillis();
        float speed = ((float) time) % 200;

//        //保存蓝牙数据
//        BluetoothData bluetoothdata = new BluetoothData();
//        bluetoothdata.setOil(Integer.parseInt(s_oil));
//        bluetoothdata.setRound(Integer.parseInt(s_rpm));
//        bluetoothdata.setSpeed(Integer.parseInt(s_speed));
//
//        BluetoothDataDao bluetoothdataDao = GlobalContext.getDaoSession().getBluetoothDataDao();
//        bluetoothdataDao.insert(bluetoothdata);

    }
}
